<?php

class rightNestedMenuComponents extends myComponents
{
    public function executeRender()
    {
        // Init models
        $groups   = new ProductGroup();
        $products = new Product();
        $object   = $this->getRoute()->getObject();
        $c_object = $this->getRoute()->getCategoryObject();
        $p_object = $this->getRoute()->getProductObject();
        
        // Init properties
        $this->categories = array();
        
        foreach($groups->getConnectedGroups($this->getUser(), $object->getId()) as $j => $group)
        {
            $this->categories[$j]['category']  = $group;
            $this->categories[$j]['products']  = array();
            $this->categories[$j]['is_active'] = false;
            
            if($c_object && $group['id'] == $c_object->getId())
            {
                $this->categories[$j]['is_active'] = true;
                
                // Trying to get category products
                foreach($products->getLastCategoryProducts($this->getUser(), $c_object->getId()) as $i => $product)
                {
                    $this->categories[$j]['products'][$i] = $product;
                    $this->categories[$j]['products'][$i]['is_selected'] = false;
                    
                    if($p_object && $product['id'] == $p_object->getId())
                    {
                        $this->categories[$j]['products'][$i]['is_selected'] = true;
                    }
                }
            }
        }
    }
};